package com.elong.qadev.tool;

import java.util.Map;
import java.util.Random;
import java.util.regex.Matcher;
/**
 * 
* @ClassName: StringUtils
* @Description: TODO(定义${}变量格式提取的字符串替换工具类)
* @author kangchen
* @date 2015年9月30日
*
 */
public class StringUtils {
	public static String replaceAfterContent(String str,Map<String,String> map){
		if (null == str) {
            return null;
        }
        for (String key : map.keySet()) {
            String param = String.format("\\$\\{%s\\}", key);
            String value = map.get(key);
            str = str.replaceAll(param, Matcher.quoteReplacement(value));
        }
		return str;
	}
	
	public static String getRandomStringByNumber(int length){
		String base = "abcdefghijklmnopqrstuvwxyz0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		String value = sb.toString();
		return value;
	}
}
